from random import randint


# 猜谜游戏
# 程序选择一个数字让用户来猜，在每一次猜测时，程序将告诉用户他猜的数字比神秘数字大还是小，用户猜中数字时游戏结束
def play():
    random_int = randint(0, 100)
    user_guess = 0
    flag = 0

    start_number = 0
    end_number = 100
    while True:
        if flag == 1:
            start_number = user_guess if user_guess >= 0 else user_guess
        if flag == 2:
            end_number = user_guess if user_guess <= 100 else user_guess

        user_guess = int(input(f"请在({start_number}-{end_number})之间猜一个数?"))

        if user_guess == random_int:
            print(f"你猜的数字 ({random_int})对了，恭喜！")
            break

        if user_guess < random_int:
            flag = 1
            print(f"你猜的数字小于标准答案")

        if user_guess > random_int:
            flag = 2
            print(f"你猜的数字大于标准答案")


if __name__ == '__main__':
    play()
